package com.lgd.warehousemanagement.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.warehousemanagement.Bean.WorkHourCache;
import com.lgd.warehousemanagement.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2025/1/16 13:52
 *   异常工单 适配器
 */
public class AbnormalOrderAdapter extends BaseAdapter {
    private Context context;
    private List<WorkHourCache> workHourCacheList;

    public AbnormalOrderAdapter(Context context, List<WorkHourCache> workHourCacheList) {
        this.context = context;
        this.workHourCacheList = workHourCacheList;
    }

    @Override
    public int getCount() {
        return workHourCacheList != null ? workHourCacheList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return workHourCacheList != null ? workHourCacheList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder;
        if (view == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.listview_abnormal_order, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_project_info = view.findViewById(R.id.tv_project_info);
            viewHolder.tv_start_time = view.findViewById(R.id.tv_start_time);
            viewHolder.tv_project_status = view.findViewById(R.id.tv_project_status);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        // 设置数据
        WorkHourCache workHourCache = workHourCacheList.get(position);
        viewHolder.tv_project_info.setText(workHourCache.getProjectname() + "（" + workHourCache.getProductacode() + "）");
        viewHolder.tv_start_time.setText(workHourCache.getStarttime());
        viewHolder.tv_project_status.setText("打卡异常订单");

        return view;
    }
    // 定义一个内部类，用来存放控件
    private static class ViewHolder{
        TextView tv_project_info, tv_start_time, tv_project_status;
    }
}
